import { BubbleDt, DataTable } from "../../../Framework/Common/CommonInterface";
import Emitter from "../../../Framework/Common/Emitter";
import Player from "./Player";

const { ccclass, property } = cc._decorator;
@ccclass
export default class Bubble extends cc.Component {
    //保存释放泡泡的玩家
    private _owner: Player = null;
    get owner() {
        return this._owner;
    }
    set owner(player: Player) {
        this._owner = player;
    }
    //存储泡泡自己的格子坐标
    private _bubbleTiledPos: cc.Vec2 = cc.v2();
    get bubbleTiledPos() {
        return this._bubbleTiledPos;
    }
    set bubbleTiledPos(tiledPos: cc.Vec2) {
        this._bubbleTiledPos = tiledPos;
    }
    private _power: number = 0;
    get power() {
        return this._power;
    }
    //存储泡泡的名字，可以通过名字获取泡泡所在的对象池
    private _bubbleName: string = "";
    get bubbleName() {
        return this._bubbleName;
    }
    set bubbleName(name: string) {
        this._bubbleName = name;
    }
    //存储水花的名字
    private _blastName: string = "";
    get blastName() {
        return this._blastName;
    }
    private _bubbleDt: BubbleDt = null;
    onInit(owner: Player, bubbleDt: BubbleDt) {
        this._owner = owner;
        this._power = this._owner.playerDt.bubblePower;
        this._bubbleDt = bubbleDt;
        this._blastName = this._bubbleDt.blastName;
        //释放泡泡3秒后泡泡爆炸
        this.scheduleOnce(this.bomb, 1.0);
    }
    //通知toBomb函数执行爆炸逻辑
    //需要知道泡泡的位置，玩家的威力
    bomb() {
        Emitter.instance.emit("ToBomb", this, this._bubbleTiledPos, this._power);
    }
}
